import QtQuick.Controls 2.15
import QtQuick 2.12
import com.rooyeetone.vnc 1.0
import QtQuick.Window 2.12

Item {
    width: 800
    height: 600
    enabled: true
    anchors.fill: parent
    focus:true
        ScrollView {
            anchors.fill: parent
            contentHeight: vncViewer.height
            contentWidth: vncViewer.width
            clip: true
            VncViewer {
                id: vncViewer
                enabled: true
                //anchors.fill: parent
                transformOrigin:Qt.TopLeftCorner
                anchors.centerIn: parent
                focus: true
                host: "47.104.147.243"
                //host: "192.168.137.227"
                port: 5902
                password: "windaka!"
                scale: 0.6
                onError: {
                    timer.start()
                    console.log("=============================onError",errorString,"=======================================")
                }
                onPropChanged: console.log("===================vncViewer",vncViewer.serverWidth,vncViewer.serverHeight,"========================")
            }
    }

    Timer {
        id:timer
        interval: 1000;
        running: false;
        repeat: false
        onTriggered: Qt.quit()
    }

    Button {
        id:stop
        anchors.right: parent.right
        width:100
        height: 100
        onClicked: vncViewer.stop()
        text: "stop"
    }
    Button {
        anchors.right: stop.left
        width:100
        height: 100
        onClicked: {
//             if(vncViewer.host === "192.168.137.227") {
//                vncViewer.host = "10.19.129.124"
//                vncViewer.port = 5901
//                vncViewer.password  = ""
//             }
//             else {
//                 vncViewer.host = "192.168.137.227"
//                 vncViewer.port = 5903
//                 vncViewer.password  = ""
//             }
             vncViewer.start()
        }
        text: "start"
    }
    Keys.onPressed: {
        //var result = vncViewer.eventMyKey(event.key, event.modifiers, event.nativeScanCode, event.text, event.isAutoRepeat, event.count);
        //vncViewer.eventMyKey(event.key, event.text, true)
        //event.accepted = true
        //console.log("======33333=========",accepted,"===========================================")
    }
    Keys.onReleased: {
        //var result = vncViewer.eventMyKey(event.key, event.modifiers, event.nativeScanCode, event.text, event.isAutoRepeat, event.count);
       // vncViewer.eventMyKey(event.key, event.text, false)
        //event.accepted = true
        //console.log("======33333=========",accepted,"===========================================")
    }
    Component.onCompleted: {
        vncViewer.start()
    }
}
